<!DOCTYPE html>
<html lang="en">
<?php
	require_once('inc/weixiconfig.php');
	require_once('globals.php');
?>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=0.5,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>我的订单</title>
    <link rel="stylesheet" href="static/css/main.css">
    <link rel="stylesheet" href="static/css/order.css">
    <link href="https://cdn.bootcss.com/sweetalert/1.1.3/sweetalert.min.css" rel="stylesheet">
    <style>
        .redtip{
            color:#e53935;
            font-size:24px;
            float:right;
        }
		.weight{
			font-size: 32px !important;
			font-weight: bold !important;
		}
    </style>
</head>
<body>
    <div id="myorder_detailcon">
        <script type="text/html" id="orderconTemp">
            <div class="topbox">
                <div class="zhuangtai">
                    {{if data.status == 0}}
                        <span class="spn1">已取消</span>
                    {{else if data.status == 1}}
                        <span class="spn1">待支付</span>
                    {{else if data.status == 2 || data.status == 3}}
                        <span class="spn1">已预约</span>
                    {{else}}
                    <span class="spn1">已完成</span>
                    {{/if}}
                    <span class="spn2">费用:￥{{data.subsist}}</span>
                </div>
                <div class="orderbox">
                    <span class="spn1" style="width:63%;font-size:23px;">订单号：{{data.order_number}}</span>
                    <span class="spn2" style="width:36%;font-size:23px;">{{data.createtime}}</span>
                </div>
                <div class="con">
                    {{if data.type == 3}}
                    <div class="classname list">专家名称：<span>{{data.class_name}}</span></div>
                    {{else}}
                    <div class="classname list">课程名称：<span>{{data.class_name}}</span></div>
                    {{/if}}
                    {{if data.type == 3}}
                     <div class="time list">预约日期：{{data.createtime}} <span class="redtip">具体时间参看短信通知</span></div>
                    {{else}}
                     <div class="time list">课程日期：{{data.createtime}}</div>
                    {{/if}}
                    <div class="obj list">课程对象：{{data.realname}}</div>
                    <div class="phone list">联系电话：{{data.mobile}}</div>
                     <div class="list" style="margin-top:-30px">备注留言：{{data.remark}}</div>
                </div>
            </div>
            <div class="spnbox">
                <div class="spn1">如遇到任何问题，请联系您的</div>
                <div class="spn2">客服专员小童：<span class="weight" style="font-size:60px;font-weight:bold;line-height:60px">0571-28284036转168</span></div>
            </div>
            {{if data.status == 1}}
            <div class="tip" style="margin-bottom:350px;">取消订单</div>
			<div class="btmbox">
	            <div class="closeorder btn">订单金额&nbsp;&nbsp;¥{{data.subsist}}</div>
	            <div class="gopay btn">去支付</div>
	        </div>
            {{/if}}
        </script>
    </div>
</body>
</html>
<script src="http://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
<script src="http://cdn.bootcss.com/sweetalert/1.1.3/sweetalert.min.js"></script>
<script src="js/aui-art-template-a880d14/lib/template-web.js" charset="utf-8"></script>
<?php
$wxjs=1;
require_once('include.php');
?>
<script type="text/javascript">
	// wx.ready(function(){
	// 	wx.hideMenuItems({
	// 		menuList: [
	// 			'menuItem:share:appMessage',
	// 			'menuItem:share:timeline',
	// 			'menuItem:share:qq',
	// 			'menuItem:share:weiboApp',
	// 			'menuItem:share:facebook',
	// 			'menuItem:share:QZone',
	// 			'menuItem:favorite'
	// 		] // 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
	// 	});
	// });
    $().ready(function(){
        var params= decodeURI(window.location.search);
        var arr = params.substring(1).split("=");
        $.ajax({
            type : "GET",
            async:false,
            url: 'http://www.familyandtree.com/getcontent.php?ac=order_info',
            dataType : "json",
            data:{
                order_id:arr[1]
            },
            success : function(data){
				alert(56)
				data.data.createtime = data.data.createtime.substring(0,16);
                $('#myorder_detailcon').html(template('orderconTemp',data));
                var order_num = data.data.order_number;
                var orderid = data.data.tbid;
                var status = data.data.status;
                $('.tip').click(function(){
                    closeorder(orderid);
                })
                $('.gopay').click(function(){
                    getpaydetail(order_num);
                })
            },
            error:function(){
                alert('fail');
            }
        });
        function closeorder(orderid){
            $.ajax({
				type : "POST",
				async:false,
				url: 'http://www.familyandtree.com/getcontent.php?ac=close_order',
				data:{
					order_id:orderid
				},
				dataType : "json",
				success : function(data){
					swal({
						button: false,
						title: "订单已关闭",
					});
					window.location.href='myorder.php'
				},
				error:function(data){
					swal({
						button: false,
						title: data.error,
					});
				}
			});
        };

        function getpaydetail(ordernumber){
			$.ajax({
				type : "POST",
				async:false,
				url: 'http://www.familyandtree.com/getcontent.php?ac=trade_pay',
				data:{
					ordernumber:ordernumber
				},
				dataType : "json",
				success : function(data){
					WeixinJSBridge.invoke(
						'getBrandWCPayRequest', {
							"appId" : "wx58c39a575f4eec96",     //公众号名称，由商户传入
							"timeStamp": data.data.timestamp,         //时间戳，自1970年以来的秒数
							"nonceStr" : data.data.noncestr, //随机串
							"package" : "prepay_id="+data.data.prepay_id,
							"signType" : "MD5",         //微信签名。方式：
							"paySign" :  data.data.sign //微信签名
						},
						function(res){
							if(res.err_msg == "get_brand_wcpay_request:ok" ) {
								window.location.href='order_list.php'
							}else if(res.err_msg == "get_brand_wcpay_request:cancel" ) {
								swal({
									button: false,
									title: '交易已取消~',
								});
							}else{
								swal({
									button: false,
									title: '支付失败！',
								});
							}     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
						}
					);
				},
				error:function(data){
					swal({
						button: false,
						title: data.error,
					});
				}
			});
		}
    })
</script>
